package de.playmee.views;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

public class ViewPagerAdapter extends PagerAdapter implements ViewPagerIndicator.PageInfoProvider {
	
	private List<View> views;
	private List<String> titles;
	
	public ViewPagerAdapter(Context context) {
		views = new ArrayList<View>();
		titles = new ArrayList<String>();
	}
	
	public void addView(View view, String title) {
		views.add(view);
		titles.add(title);
	}

	@Override
	public int getCount() {
		return views.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}
	
	@Override
	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView((View) object);
	}
	
	@Override
	public Object instantiateItem(View container, int position) {
		View view = views.get(position);
		((ViewPager) container).addView(view);
		return view;
	}

	@Override
	public String getTitle(int pos) {
		return titles.get(pos);
	}
}
